/**
 * Created by hcadmin on 17/4/25.
 */
(function ($) {
    $.extend({
        watchBigPic: function (_self) {
            $('.big_img').remove();
            var img_src = _self.attr('src');

            //debugger;

            var call_back = document.createElement('div');
            call_back.setAttribute('class', 'img_back');
            call_back.style.position = 'fixed';
            call_back.style.left = 0;
            call_back.style.top = '0';
            call_back.style.marginLeft = 'auto';
            call_back.style.marginRight = 'auto';
            call_back.style.overflow = 'auto';
            call_back.style.zIndex = '9999';
            call_back.style.width = '100%';
            call_back.style.height = '100%';
            call_back.style.textAlign = 'center';
            call_back.style.background = 'rgba(0, 0, 0,0.8)';

            var img = document.createElement('img');
            img.src = img_src;
            img.setAttribute('class', 'big_img');
            img.style.marginLeft = 'auto';
            img.style.marginRight = 'auto';

            call_back.appendChild(img);
            document.documentElement.appendChild(call_back);

            var width = $('.big_img').css('width').split("px")[0];
            var height = $('.big_img').css('height').split("px")[0];


            var clientWidth = $(window).width();
            var clientHeight = $(window).height();

            //console.log(width);
            //console.log(height);
            //console.log(width / height);
            if (width / height >= parseFloat(clientWidth)/parseFloat(clientHeight)) {
                $('.big_img').css('width', '100%');
                $('.big_img').css('height', 'auto');
                var hei=$('.big_img').height();
                //console.log(hei);
                $('.big_img').css('paddingTop', (clientHeight-hei)/2 + "px");
                    //(100-hei/clientHeight*100)+'%');
            } else {
                $('.big_img').css('height', '100%');
                $('.big_img').css('width','auto');
            }

            //点击移除隐藏
            $('.img_back').on('click', function () {
                $(this).remove();
            });

        }
    });
})(jQuery);